#include "GameWindow.h"

GameWindow::GameWindow() :
	window(VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), WINDOW_TITLE),
			map(WINDOW_PLAYER, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BOARDER) {
}

GameWindow::~GameWindow() {
	// empty
}

void GameWindow::handleWindow() {
	while (window.IsOpened()) {
		event = Event();
		while (window.GetEvent(event)) {
			handleEvent();
		}
		handleMap();
		Sleep(0.01f);
		window.Display();
	}
}

void GameWindow::handleEvent() {
	if (event.Type == Event::Closed) {
		window.Close();
	}
	if (event.Type == Event::KeyPressed) {
		if (event.Key.Code == Key::Escape) {
			window.Close();
		}
		if (event.Key.Code == Key::F2) {
			map.reset();
		}
	}
}

void GameWindow::handleMap() {
	map.checkForCollisions();
	map.update(window.GetFrameTime());
	map.render(window);
}
